package com.lanyun.controller;

import com.lanyun.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/*
    销售统计
 */
@Controller
public class StatController {

    /*
        销售统计,暂时用StockService 先实现功能,后期整合代码
     */
    @Autowired
    private StockService stockService;
/*
销售统计
 */
    @RequestMapping("/showStat")
    public String showCount(Map map,String begin,String end) throws ParseException {
        List<Map<String, Object>> lists = stockService.showStatAll(begin,end);//销售统计，并根据时间查询
        map.put("begin",begin);
        map.put("end",end);
        map.put("lists",lists);
        return "stat";
    }

//    @RequestMapping("/statRefresh")
//    public String stat(Map map,String begin,String end){
//        System.out.println(begin+"======================");
//        System.out.println(end+"===========================");
//        List<Map<String, Object>> lists = stockService.showStatAll(begin,end);//销售统计，并根据时间查询
//        map.put("lists",lists);
//        return "stat::pageInfo";
//    }

    /*
    销售趋势
     */
    @RequestMapping("/showTrend")
    public String showTrend(Map map,Integer years){
        String begin;
        String end;
        if(years==null){
            begin  = "2021-01-01";
            end = "2022-01-01";
        }else{
            begin = years+"-01-01";
            end = years+1+"-01-01";
        }
        List<String> year = stockService.getYear();//年份信息，给下拉列表赋值
        List<Map<String, Object>> lists = stockService.showTrend(begin,end);//销售趋势
        map.put("lists",lists);
        map.put("year",year);
        return  "trend";
    }


}
